package com.mzx.javase.io;

import javax.lang.model.element.VariableElement;
import java.io.*;

/**
 * 类描述：通过使用对比BufferedInputStream和BufferedOutputStream
 *
 * @ClassName BufferedFileCopy
 * @Description TODO
 * @Author 马子鑫
 * @Date 2022/7/31 15:03
 * @Version 1.0
 */
public class BufferedFileCopy {
    public static void main(String[] args) {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream("D:\\软件安装包\\jdk-8u333-windows-x64.exe"));
            bos = new BufferedOutputStream(new FileOutputStream("D:\\java\\tempdirectory\\jdk8.exe"));
            long startTime = System.currentTimeMillis();
            byte[] bytes = new byte[1024];//一次复制1kb的数据
            int len = 0;
            while ((len = bis.read(bytes)) != -1) {
                bos.write(bytes,0,len);
            }
            long endTime = System.currentTimeMillis();
            System.out.println((endTime - startTime) + "毫秒");
            bos.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
